/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interface;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.File;
import java.util.Vector;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import moteur.Transport;
import moteur.carte.Chemin;
import moteur.carte.EmplacementLegal;
import moteur.carte.editor.Graphe;
import moteur.carte.MouvementLegal;
import moteur.carte.Ville;
import moteur.partie.Jouer;
import moteur.partie.Partie;

/**
 *
 * @author Administrateur
 */
public class AffichagePions extends JPanel {
    private Graphe graphe;
    private Image[] bottes = new Image[6];
    private Vector<EmplacementLegal> el;
    private Vector<MouvementLegal> ml;

    /**
     * 
     */
    public AffichagePions() {
       setOpaque(false);

    try{
        bottes[0] = ImageIO.read(new File(getClass().getResource("images/botte1.png").getFile()));
        bottes[1] = ImageIO.read(new File(getClass().getResource("images/botte2.png").getFile()));
        bottes[2] = ImageIO.read(new File(getClass().getResource("images/botte3.png").getFile()));
        bottes[3] = ImageIO.read(new File(getClass().getResource("images/botte4.png").getFile()));
        bottes[4] = ImageIO.read(new File(getClass().getResource("images/botte5.png").getFile()));
        bottes[5] = ImageIO.read(new File(getClass().getResource("images/botte6.png").getFile()));
        
    }catch(Exception e){}
       graphe = Partie.getInstance().getG();
    }

    public Vector<EmplacementLegal> getEl() {
        return el;
    }

    public void setEl(Vector<EmplacementLegal> el) {
        this.el = el;
        repaint();
    }

    public Vector<MouvementLegal> getMl() {
        return ml;
    }

    public void setMl(Vector<MouvementLegal> ml) {
        this.ml = ml;
        repaint();
    }

     @Override
    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;

        Vector<Chemin> v = graphe.getListeChemin();
        Vector<Jouer> w = Partie.getInstance().getJoeurs();
        Jouer j = null;

        for(int i = w.size(); --i >= 0;){
            j = w.get(i);
            Ville b = j.getLocalisation();
            g2.drawImage(bottes[i], (int)(b.getX()*1024 + (i/2) * 15), (int)(b.getY()*1024 + (i%2)*20), null);
        }

        if(ml == null){
                for(Chemin c : v){
                    if(c.getPionTransport() != null){
                        int x = (int)(c.getX()*1024);
                        int y = (int)(c.getY()*1024);
                        g2.drawImage(c.getPionTransport().getImage(), x, y, null);
                    }
                }
                    
               if(el != null){
                   for(EmplacementLegal e: el){
                    int x = (int)(e.getC().getX()*1024);
                    int y = (int)(e.getC().getY()*1024);
                    g2.drawImage(Transport.getImageDefaut(), x, y, null);
                }
               }

        }else{
            for(MouvementLegal e: ml){
                int x = (int)(e.getDest().getX()*1024);
                int y = (int)(e.getDest().getY()*1024);
                Integer i = new Integer(e.getCost());
                if(e.getT() == null){
                    g2.drawString( i.toString() +" QCQ" , x, y + 15 );
                }else{
                    g2.drawString( i.toString() +" "+e.getT().name() , x, y);
                }
            }

        }
        /*test
        g.drawRect(0, 10, 70, 45);
        //*/
    }

}
